package com.water.dmdb.th;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class Th implements ThreadFactory {
    private String namePrefix;
    private AtomicInteger nextId = new AtomicInteger();

    public Th(String whatFeatureOfGroup) {
        namePrefix = "From UserThreadFactory's " + whatFeatureOfGroup + "-Worker-";
    }

    @Override
    public Thread newThread(Runnable task) {
        String name = namePrefix + nextId.getAndIncrement();
        Thread thread = new Thread(task,name);
        System.out.println(thread.getName());
        return thread;
    }

    public static void main(String[] args) {
        Th th = new Th("saasas");
        th.newThread(new Runnable() {
            @Override
            public void run() {

            }
        }).start();
    }
}
